import {createRouter, createWebHashHistory} from 'vue-router'
import { isMobile } from "@/utils/device.js";

const viewport = {
  content: 'width=device-width, initial-scale=1.0, user-scalable=no',
}

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      redirect: '/home',
    },
    {
      path: '/home',
      name: 'Home',
      component: () => import('@/views/home/index.vue'),

    },
    {
      path:'/open',
      name:'open',
      component: () => import('@/views/login/open.vue')
    },
    {
      path: "/login",
      name: "login",
      component: () => import('@/views/login/login.vue'),
    },
    {
      path: "/limits",
      name: "limits",
      component: () => import('@/views/home/Limits.vue'),
    },
    {
      path: "/inforRelease",
      name: "inforRelease",
      component: () => import('@/views/home/InforRelease.vue'),
    },
    {
      path: "/document",
      name: "document",
      component: () => import('@/views/home/Document.vue'),
    },
    {
      path: "/publish",
      name: "publish",
      component: () => import('@/views/home/Publish.vue'),
    },
    {
      path: "/read",
      name: "read",
      component: () => import('@/views/home/Read.vue'),
    },
    {
      path: "/personalData",
      name: "personalData",
      component: () => import('@/views/home/PersonalData.vue'),
    },
    {
      path: "/batchPinting",
      name: "batchPinting",
      component: () => import('@/views/home/BatchPinting.vue'),
    },
    {
      path: "/carousel",
      name: "carousel",
      component: () => import('@/views/home/Carousel.vue'),
    },
    {
      path: '/workspace',
      name: 'workspace',
      component: () => import('@/views/workspace/WorkSpace.vue'),
      children: [
        {
          path: 'forms',
          name: 'forms',
          component: () => import('@/views/workspace/oa/FromsApp.vue'),
          meta: { title: 'IBPM | OA审批', viewport: viewport },
        },
        {
          path: 'submit',
          name: 'submit',
          component: () => import('@/views/workspace/oa/MySubmit.vue'),
          meta: { title: 'IBPM | 我发起的', viewport: viewport },
        },
        {
          path: 'cc',
          name: 'cc',
          component: () => import('@/views/workspace/oa/CcMe.vue'),
          meta: { title: 'IBPM | 抄送我的', viewport: viewport },
        },
        {
          path: 'unfinished',
          name: 'unfinished',
          component: () => import('@/views/workspace/oa/UnFinished.vue'),
          meta: { title: 'IBPM | 未完成的', viewport: viewport },
        },
        {
          path: 'finished',
          name: 'finished',
          component: () => import('@/views/workspace/oa/Finished.vue'),
          meta: { title: 'IBPM | 未完成的', viewport: viewport },
        },
        {
          path: 'instances',
          name: 'instances',
          component: () => import('@/views/admin/ProcessInstanceManage.vue'),
          meta: { title: 'IBPM | 数据管理', viewport: viewport },
        },
        {
          path: 'formsPanel',
          name: 'formsPanel',
          component: () => import('@/views/admin/FormsPanel.vue'),
          meta: { title: 'IBPM | 表单列表', viewport: viewport },
        },
        {
          path: "subProcess",
          name: "subProcess",
          component: () => import("@/views/admin/SubProcess.vue"),
          meta: {title: 'IBPM | 子流程管理', viewport: viewport}
        },
        {
          path: "roleManage",
          name: "roleManage",
          component: () => import("@/views/workspace/oa/RoleManage.vue"),
          meta: {title: 'IBPM | 角色管理', viewport: viewport}
        },
        {
          path: "deptAllocation",
          name: "deptAllocation",
          component: () => import("@/views/valueSetConfig/deptAllocation/deptAllocation.vue"),
          meta: {title: 'IBPM | 字典配置', viewport: viewport}
        },
        {
          path: "dictionaryConfiguration",
          name: "dictionaryConfiguration",
          component: () => import("@/views/valueSetConfig/dictionaryConfiguration/dictionaryConfiguration.vue"),
          meta: {title: 'IBPM | 接口回调', viewport: viewport}
        },
        {
          path: "errorInfo",
          name: "errorInfo",
          component: () => import("@/views/workspace/oa/ErrorInfo.vue"),
          meta: {title: 'IBPM | 接口回调', viewport: viewport}
        },
        {
          path: "report",
          name: "report",
          component: () => import("@/views/report/index.vue"),
          meta: {title: 'IBPM | 报表中心', viewport: viewport},
          children:[{
            path: 'contractManagementMF',
            name: 'contractManagementMF',
            component: () => import('@/views/report/MF/ContractManagementMF.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          },{
            path: 'paymentMF',
            name: 'paymentMF',
            component: () => import('@/views/report/MF/PaymentMF.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          },{
            path: 'reimbursementForPrivateMF',
            name: 'reimbursementForPrivateMF',
            component: () => import('@/views/report/MF/ReimbursementForPrivateMF.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          },{
            path: 'reimbursementToCorporateMF',
            name: 'reimbursementToCorporateMF',
            component: () => import('@/views/report/MF/ReimbursementToCorporateMF.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          },{
            path: 'longTermAssetReportMF',
            name: 'longTermAssetReportMF',
            component: () => import('@/views/report/MF/LongTermAssetReportMF.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          },{
            path: 'longTermAssetsPayableMF',
            name: 'longTermAssetsPayableMF',
            component: () => import('@/views/report/MF/LongTermAssetsPayableMF.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          },{
            path: 'constructionInProgressReportMF',
            name: 'constructionInProgressReportMF',
            component: () => import('@/views/report/MF/ConstructionInProgressReportMF.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          },{
            path: 'standardInventoryPayableReportMF',
            name: 'standardInventoryPayableReportMF',
            component: () => import('@/views/report/MF/StandardInventoryPayableReportMF.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          },{
            path: 'costInventoryPayableReportMF',
            name: 'costInventoryPayableReportMF',
            component: () => import('@/views/report/MF/CostInventoryPayableReportMF.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          },{
            path: 'inventoryEstimatedPayableReportMF',
            name: 'inventoryEstimatedPayableReportMF',
            component: () => import('@/views/report/MF/InventoryEstimatedPayableReportMF.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          },{
            path: 'qZBLReport',
            name: 'qZBLReport',
            component: () => import('@/views/report/HR/QZBLReport.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          },{
            path: 'wPSQReport',
            name: 'wPSQReport',
            component: () => import('@/views/report/HR/WPSQReport.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          },{
            path: 'purchaseRequestMFReport',
            name: 'purchaseRequestMFReport',
            component: () => import('@/views/report/MF/PurchaseRequestMFReport.vue'),
            meta: { title: 'IBPM | OA审批', viewport: viewport },
          }]
        }
      ],
    },
    {
      path: '/mbinitiate',
      name: 'mbinitiate',
      component: () => import('@/views/workspace/MbInitiateProcess.vue'),
      meta: { title: 'IBPM | 发起审批', viewport: viewport },
    },
    {
      path: "/mbInstance",
      name: "mbInstance",
      component: () => import("@/views/workspace/MbInstanceViewer.vue"),
      meta: {title: 'IBPM | 流程详情', viewport: viewport}
    },
    {
      path: '/admin/design',
      name: 'design',
      component: () => import('@/views/admin/FormProcessDesign.vue'),
      meta: { title: 'IBPM | 表单流程设计', viewport: viewport },
    },
    {
      path: "/testForm",
      name: "testForm",
      component: () => import("@/views/common/form/TestForm.vue"),
      meta: {title: 'IBPM | 表单演示', viewport: viewport}
    },
    {
      path: "/task",
      name: "task",
      component: () => import("@/views/task/task.vue"),
      // meta: {title: 'IBPM | 表单演示', viewport: viewport}
    }
  ],
})

router.beforeEach((to, from, next) => {
  if (isMobile()) {
    // 如果是移动设备，跳转到移动端首页
    if (!to.path.includes('/m/')) {
      // 跳转到移动端首页 http://api.eletile.com:18081/wflow
      window.location.href = 'http://api.eletile.com:18081/m/'
    }
  }
  if (to.meta.title) {
    document.title = to.meta.title
  }
  if (to.meta.content) {
    let head = document.getElementByTagName('head')
    let meta = document.createElemnet('meta')
    meta.name = 'viewport'
    meta.content = 'width=device-width, initial-scale=1.0, user-scalable=no'
    head[0].appendChild(meta)
  }
  next()
  sessionStorage.setItem('router-path', to.path)
})

export default router
